<?php
session_start();

if(isset($_SESSION['s_username'])){

	require "../connection/connection.php";
	$query = "SELECT * FROM clientes";
	$clientes = mysql_query($query);
	mysql_close();

	echo  '<ul class="thumbnails">';
	while($rowClientes = mysql_fetch_array($clientes)){
		echo	'<li>';
		echo	'	<span class="thumbnail">';
		echo    '		<i class="icon-pencil control-btn-edit" clientId="'.$rowClientes['clientesId'].'"></i>';
		echo 	'		<i class="icon-remove-sign control-btn-delete"  clientId="'.$rowClientes['clientesId'].'"></i>';
		echo	'		<img src="../actions/getImageClientes.php?id='.$rowClientes['clientesId'].'" width="176"/>';
		echo 	'	</span>';
		echo 	'</li>';
	}
	echo '</ul>';




}else{
	header ("location: ../../index.php");
}

?>

<!-- Modal -->
<div id="clienteModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-header">
		<h3 id="myModalLabel">Adjuntar imágen</h3>
	</div>
	<div class="modal-body" id="modal-body-clientes">
				
	</div>
	<div class="modal-footer">
		<button class="btn" data-dismiss="modal" aria-hidden="true">Cancelar</button>				
	</div>
</div>

<!-- confirm -->
<div id="confirmDiv"></div>


<script>
	$('.control-btn-edit').click(function(){
		var clientId = $(this).attr('clientId');
		$('#modal-body-clientes').load('phpScripts/clientes/clientesFormView.php?action=edit&clientesId='+clientId,function(){
			$('#clienteModal').modal('show');
		}); 

	});

	$(".control-btn-delete").click(function () {
		var clientesId = $(this).attr('clientId');
		$("#confirmDiv").confirmModal({
			heading: 'Eliminar cliente',
			body: '¿Desea eliminar el cliente?',
			callback: function () {
				$.ajax({
					url:'phpScripts/clientes/deleteClientesAction.php?clientesId='+clientesId,
					success:function(){
						$('#clientesABM').load('phpScripts/clientes/clientesListView.php');
					}
				});
			}
		});
	});

	
</script>

